package com.admin.interfaces.facade.assembler;

import com.admin.domain.model.User;
import com.admin.infrastructure.BeanUtil;
import com.admin.interfaces.facade.commandobject.ProfileCommand;
import com.admin.interfaces.facade.commandobject.UserCommand;
import com.admin.interfaces.facade.dto.UserDto;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * @author Jonsy
 */
public class UserAssembler {

    public static User commandToDomain(UserCommand command){
        User user = new User();
        BeanUtil.copeProperties(command, user);
        return user;
    }

    public static User commandToDomain(String uid, UserCommand command){
        User user = new User();
        BeanUtil.copeProperties(command, user);
        user.setId(uid);
        return user;
    }

    public static User profileToDomain(String uid, ProfileCommand command){
        User user = new User();
        BeanUtil.copeProperties(command, user);
        user.setId(uid);
        return user;
    }


    public static UserDto domainToDto(User user){
        UserDto dto = new UserDto();
        BeanUtil.copeProperties(user, dto);
        return dto;
    }

    public static List<UserDto> domainToDto(List<User> user){
        if(CollectionUtils.isEmpty(user)){
            return null;
        }
        List<UserDto> dtos = new ArrayList<>(user.size());
        user.stream().forEach(user1 -> {
            dtos.add(domainToDto(user1));
        });
        return dtos;
    }

}
